package Data::Maker::Field::PhoneNumber::NorthAmerica;
use Moose;
use MooseX::Aliases;
with 'Data::Maker::Field';

our $VERSION = '0.02';

# This class generates phone numbers that are mostly-consistent with the "North American Numbering Plan".
# http://en.wikipedia.org/wiki/North_American_Numbering_Plan
# This slightly-improves the realistic appearance of phone numbers, over just using any random digits.

has parenthesis => ( is => 'rw', isa => 'Bool', default => 1 );
has separator => ( is => 'rw', default => '-', alias => 'delimiter' );

sub generate_value {
  my $this = shift;
  my $area_code = $this->area_code; 
  my $exchange = $this->exchange; 
  my $number = $this->number; 
  my $format;
  if ($this->parenthesis) {
    return "($area_code)" . join($this->separator, $exchange, $number);
  } else {
    return join($this->separator, $area_code, $exchange, $number);
  }
}

sub area_code {
  return
    Data::Maker->random(2..9) . # first digit must be 2-9 
    Data::Maker->random(0..8) . # second digit must be 0-8 
    Data::Maker->random(0..9)   # third digit must be 0-9
}

sub exchange {
  return  
    Data::Maker->random(2..9) . # first digit must be 2-9
    Data::Maker->random(0..9) . # second and third digits must be 0-9 
    Data::Maker->random(0..9) 
}

sub number {
  # get a random 4-digit string, but give it a name that can be reused by Data::Maker::Field
  return Data::Maker::Field::Format->new(
    name => '_dmfpn_phone_number',
    format => '\d\d\d\d'
  )->generate->value;
}

1;
